<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');

class founder_salary extends CI_Controller
{


	function __construct()
	{
		parent::__construct();

		// check if user logged in
		if(!$this->ion_auth->logged_in()){
			redirect('auth/login');
		}
		$this->load->library('form_validation');
		$this->load->model('hrm/founder/salary_model');
	}

	function index()
	{
		$meta['page_title'] = "View All Salary";
		$meta['dashboard'] = "dashboard";	   
		//echo "i am here";exit;
		$this->data['salaries'] = $this->salary_model->get_all_salary();
		$this->load->view('common/header',$meta);
		$this->load->view('hrm/founder/view-salary',$this->data);
		$this->load->view('common/footer');
	}

	function create_salary()
	{

		$this->form_validation->set_rules('user', 'User', 'required|is_unique[salary_account.user_id]');
		$this->form_validation->set_rules('salary', 'Salary', 'required|numeric');
		$this->form_validation->set_rules('per_day_salary', 'Per day salary', 'required|numeric');
		$this->form_validation->set_rules('min_working_hour', 'MIn Working Hour', 'required|numeric');

		$this->form_validation->set_rules('per_hour_salary', 'Per Hour Salary', 'required|numeric');

		$this->form_validation->set_rules('paid_leave', 'Paid Leave Allowed', 'required|numeric');
		$this->form_validation->set_rules('per_month_leave', 'Per month leave', 'required|numeric');

		if($this->form_validation->run() == FALSE){
			$this->form_validation->set_message('user','Already Set');
			$this->form_validation->set_message('salary');
			$this->form_validation->set_message('per_day_salary');
			$this->form_validation->set_message('user');
		}
		else
		{
			$insert = array(
				'user_id'         =>$this->input->post('user'),
				'salary'          =>$this->input->post('salary'),
				'per_day_salary'  =>$this->input->post('per_day_salary'),
				'min_working_hour'=>$this->input->post('min_working_hour'),
				'per_hour_salary' =>$this->input->post('per_hour_salary'),
				'paid_leave'      =>$this->input->post('paid_leave'),
				'per_month_leave' =>$this->input->post('per_month_leave')
			);

			$this->salary_model->create_salary($insert);
			redirect('hrm/founder_salary','refresh');

		}
		$this->data['users'] = $this->ion_auth->users()->result();
		$meta['page_title'] = "Create Salary";
		$meta['dashboard'] = "dashboard";	   
	  	$this->load->view('common/header',$meta);
		$this->load->view('hrm/founder/create-salary',$this->data);
		$this->load->view('common/footer');
	}

	function edit_salary($id)
	{
		$this->form_validation->set_rules('user', 'User', 'required');
		$this->form_validation->set_rules('salary', 'Salary', 'required|numeric');
		$this->form_validation->set_rules('per_day_salary', 'Per day salary', 'required|numeric');
		$this->form_validation->set_rules('min_working_hour', 'MIn Working Hour', 'required|numeric');

		$this->form_validation->set_rules('per_hour_salary', 'Per Hour Salary', 'required|numeric');

		$this->form_validation->set_rules('paid_leave', 'Paid Leave Allowed', 'required|numeric');
		$this->form_validation->set_rules('per_month_leave', 'Per month leave', 'required|numeric');

		if($this->form_validation->run() == FALSE){
			$this->form_validation->set_message('user','Already Set');
			$this->form_validation->set_message('salary');
			$this->form_validation->set_message('per_day_salary');
			$this->form_validation->set_message('user');
		}
		else
		{
			$update = array(
				'user_id'         =>$this->input->post('user'),
				'salary'          =>$this->input->post('salary'),
				'per_day_salary'  =>$this->input->post('per_day_salary'),
				'min_working_hour'=>$this->input->post('min_working_hour'),
				'per_hour_salary' =>$this->input->post('per_hour_salary'),
				'paid_leave'      =>$this->input->post('paid_leave'),
				'per_month_leave' =>$this->input->post('per_month_leave')
			);

			$this->salary_model->update_salary($update,$id);
			redirect('hrm/founder_salary','refresh');

		}
		
		
		
		$this->data['users'] = $this->ion_auth->users()->result();
		$this->data['salary']= $this->salary_model->get_salary($id);
		$meta['dashboard'] = "dashboard";	  
		$meta['page_title'] = "Edit Salary";
		$this->load->view('common/header',$meta);
		$this->load->view('hrm/founder/edit-salary',$this->data);
		$this->load->view('common/footer');
	}
	/* public function username_check($str)
	{
	$this->salary_model->check_duplicate_entry($str);

	if ($str == 'test')
	{
	$this->form_validation->set_message('user', 'Salary Already Set For This Person');
	return FALSE;
	}
	else
	{
	return TRUE;
	}
	}*/



}

?>